package com.zhuiyun.educations.api.rotationimage.controller;

import com.zhuiyun.educations.api.rotationimage.entity.ImageFile;
import com.zhuiyun.educations.api.rotationimage.entity.RotationImage;
import com.zhuiyun.educations.api.rotationimage.service.RotationImageService;
import com.zhuiyun.educations.common.response.CommonResult;
import com.zhuiyun.educations.util.pageUtil.PageRequest;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName RotationImageController
 * @Description TODO 轮播图控制层
 * @Author 杨友朋
 * @Date 2023/6/21 10:28
 **/
@CrossOrigin
@RestController
@RequestMapping("/rotationImage")
public class RotationImageController {
    @Resource
    RotationImageService rotationImageService;

    /**
    * @Author 杨友朋
    * @Description TODO 查询所有轮播图信息
    * @Date 2023/6/21 20:17
    * @Return
    * @param rotationImage，pageRequest
    */
    @GetMapping("/selectRotationImage")
    public CommonResult selectRotationImage(RotationImage rotationImage, PageRequest pageRequest){
        return CommonResult.ok(rotationImageService.selectRotationImage(rotationImage,pageRequest));
    }

    /**
    * @Author 杨友朋
    * @Description TODO 添加单个图片
    * @Date 2023/6/21 20:18
    * @Return
    * @param file，rotationImage，imageFile
    */
    @PostMapping("addRotationImage")
    public CommonResult addImageFile(MultipartFile file, RotationImage rotationImage, ImageFile imageFile){
        return rotationImageService.addRotationImage(file,rotationImage,imageFile);
    }

    /**
    * @Author 杨友朋
    * @Description TODO 添加多个图片
    * @Date 2023/6/21 20:19
    * @Return
    * @param file，rotationImage，imageFile
    */
    @PostMapping("addRotationImages")
    public CommonResult addImageFiles(MultipartFile[] file, RotationImage rotationImage,ImageFile imageFile){
        return rotationImageService.addRotationImages(file,rotationImage,imageFile);
    }

    /**
    * @Author 杨友朋
    * @Description TODO 根据id删除
    * @Date 2023/6/21 20:19
    * @Return
    * @param id
    */
    @GetMapping("/deleteRotationImage")
    public CommonResult deleteRotationImage(Integer id){
        return rotationImageService.deleteRotationImage(id);
    }

    /**
    * @Author 杨友朋
    * @Description TODO 根据ids批量删除
    * @Date 2023/6/21 20:20
    * @Return
    * @param ids
    */
    @PostMapping("/deleteImageByIds")
    public CommonResult deleteImageByIds(@RequestBody List<Integer> ids) {
        return rotationImageService.deleteImageByIds(ids);
    }
}
